package parts3.lesson35;

public class MyThread implements Runnable {
    private int ticket = 10;

    @Override
    public void run() {
        for (int x = 0; x < 20; x++) {
            if (this.ticket > 0) {
                try {
                    /**
                     * 模拟网络延迟1秒，就可能出现同一张票多个人同时卖出了
                     * 也有可能多卖出了一张票，变成了0
                     */
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName() + "卖票，ticket=" + this.ticket--);
            }
        }
    }
}
